This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(tidyverse)
[30m── [1mAttaching packages[22m ───────────────────────────────────────────────────── tidyverse 1.2.1 ──[39m
[30m[32m✔[30m [34mtibble [30m 2.1.3 [32m✔[30m [34mpurrr [30m 0.3.2
[32m✔[30m [34mtidyr [30m 0.8.3 [32m✔[30m [34mstringr[30m 1.4.0
[32m✔[30m [34mreadr [30m 1.3.1 [32m✔[30m [34mforcats[30m 0.4.0[39m
[30m── [1mConflicts[22m ──────────────────────────────────────────────────────── tidyverse_conflicts() ──
[31m✖[30m [34mlubridate[30m::[32mas.difftime()[30m masks [34mbase[30m::as.difftime()
[31m✖[30m [34mdplyr[30m::[32mbetween()[30m masks [34mdata.table[30m::between()
[31m✖[30m [34mtidyr[30m::[32mcomplete()[30m masks [34mRCurl[30m::complete()
[31m✖[30m [34mlubridate[30m::[32mdate()[30m masks [34mbase[30m::date()
[31m✖[30m [34mdplyr[30m::[32mfilter()[30m masks [34mplotly[30m::filter(), [34mstats[30m::filter()
[31m✖[30m [34mdplyr[30m::[32mfirst()[30m masks [34mdata.table[30m::first()
[31m✖[30m [34mlubridate[30m::[32mhour()[30m masks [34mdata.table[30m::hour()
[31m✖[30m [34mlubridate[30m::[32mintersect()[30m masks [34mbase[30m::intersect()
[31m✖[30m [34mlubridate[30m::[32misoweek()[30m masks [34mdata.table[30m::isoweek()
[31m✖[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()
[31m✖[30m [34mdplyr[30m::[32mlast()[30m masks [34mdata.table[30m::last()
[31m✖[30m [34mlubridate[30m::[32mmday()[30m masks [34mdata.table[30m::mday()
[31m✖[30m [34mlubridate[30m::[32mminute()[30m masks [34mdata.table[30m::minute()
[31m✖[30m [34mlubridate[30m::[32mmonth()[30m masks [34mdata.table[30m::month()
[31m✖[30m [34mlubridate[30m::[32mquarter()[30m masks [34mdata.table[30m::quarter()
[31m✖[30m [34mlubridate[30m::[32msecond()[30m masks [34mdata.table[30m::second()
[31m✖[30m [34mlubridate[30m::[32msetdiff()[30m masks [34mbase[30m::setdiff()
[31m✖[30m [34mpurrr[30m::[32mtranspose()[30m masks [34mdata.table[30m::transpose()
[31m✖[30m [34mlubridate[30m::[32munion()[30m masks [34mbase[30m::union()
[31m✖[30m [34mlubridate[30m::[32mwday()[30m masks [34mdata.table[30m::wday()
[31m✖[30m [34mlubridate[30m::[32mweek()[30m masks [34mdata.table[30m::week()
[31m✖[30m [34mlubridate[30m::[32myday()[30m masks [34mdata.table[30m::yday()
[31m✖[30m [34mlubridate[30m::[32myear()[30m masks [34mdata.table[30m::year()[39m
library(neonUtilities)
library(phenocamapi)
library(lubridate)
library(jpeg)
library(phenocamr)
library(plotly)
sites <- c("ONAQ", "HARV", "CPER", "OSBS")
## from tutorial https://www.neonscience.org/eddy-data-intro
# zipsByProduct(dpID="DP4.00200.001", package="basic",
# site=sites,
# #startdate="2018-06", enddate="2018-07",
# savepath="/data",
# check.size=F)
#
# flux_dpid <- "DP4.00200.001"
# flux <- stackEddy(filepath=paste0(getwd(), "/neonsummit/data/filesToStack00200"),
# level="dp04")
# phe_dpid <- 'DP1.10055.001'
# zipsByProduct(dpID='DP1.10055.001', package ="basic",
# site=sites,
# savepath="data",
# check.size = F)
#
# stackByTable(phe_dpid, filepath=paste0(getwd(), "/filesToStack10055"),
# savepath = paste0(getwd(), "/filesToStack10055"), folder=T,
# saveUnzippedFiles = FALSE) #phe data
#### save locally, cannot push to git too big #####
statusIntensity <- read.csv(paste0(getwd(),'/stackedFiles/phe_statusintensity.csv'),
stringsAsFactors = F, header = T)
perind <- read.csv(paste0(getwd(), '/stackedFiles/phe_perindividual.csv'),
stringsAsFactors = F, header = T)
#Format dates
statusIntensity$date <- as.Date(statusIntensity$date, "%Y-%m-%d")
statusIntensity$editedDate <- as.Date(statusIntensity$editedDate, "%Y-%m-%d")
statusIntensity$dayOfYear <- yday(statusIntensity$date)
statusIntensity$year <- substr(statusIntensity$date, 1, 4)
statusIntensity$monthDay <- format(statusIntensity$date, format="%m-%d")
#remove duplicate records
statusIntensity <- select(statusIntensity, -uid)
statusIntensity <- distinct(statusIntensity)
si_last <- statusIntensity %>%
group_by(individualID, date, phenophaseName) %>%
filter(editedDate==max(editedDate))
perind <- select(perind, individualID, growthForm, taxonID, editedDate)
perind <- distinct(perind)
ind_last <- perind %>%
group_by(individualID) %>%
filter(editedDate==max(editedDate))
ind_last <- select(ind_last, -editedDate)
si_last <- left_join(si_last, ind_last)
Joining, by = "individualID"
df <- filter(si_last,
siteID%in%c('HARV', 'OSBS', 'ONAQ')
& year>2015
& phenophaseStatus=='yes'
#& taxonID%in%c('QUFA', 'QULA2')
#& growthForm=='Deciduous broadleaf'
& phenophaseName%in%c('Breaking leaf buds', 'Initial growth', 'Emerging needles')
#& phenophaseIntensity !=""
)
df_out <- df%>%
group_by(siteID, taxonID, date)%>%
summarise(count=n())%>%
arrange(date)
ggplot(df_out, aes(x=date, y=count)) +
#, group=taxonID)) +
geom_line(aes(color=siteID), size=1)+
ylim(0, 30)+
facet_grid(siteID ~ .)
ggsave('SpringPhe_inSitu.png')
Saving 7.1 x 4.39 in image
p = plot_ly() %>%
add_trace(
data = df_out[df_out$siteID=='HARV',],
x = ~ date,
y = ~ count,
name = 'HARV',
showlegend = TRUE,
type = 'scatter',
mode = 'marker'
)
p2 = plot_ly() %>%
add_trace(
data = df_out[df_out$siteID=='OSBS',],
x = ~ date,
y = ~ count,
name = 'OSBS',
showlegend = TRUE,
type = 'scatter',
mode = 'marker'
)
p3 = plot_ly() %>%
add_trace(
data = df_out[df_out$siteID=='ONAQ',],
x = ~ date,
y = ~ count,
name = 'ONAQ',
showlegend = TRUE,
type = 'scatter',
mode = 'marker'
)
p_all <- subplot(p, p2, p3, nrows = 3)
p_all
## can't figure out how to save as .png ###